// utils/ApiError.js
class ApiError extends Error {
    /**
     * @param {string} message
     * @param {number} status HTTP status code
     * @param {string|number|null} [code] 自定义错误码（可选）
     */
    constructor(message, status = 400, code = null) {
        super(message);
        this.name = 'ApiError';
        this.status = status;
        this.code = code;
        Error.captureStackTrace(this, this.constructor);
    }

    static BadRequest(msg = 'Bad Request') {
        return new ApiError(msg, 400);
    }
    static Unauthorized(msg = 'Unauthorized') {
        return new ApiError(msg, 401);
    }
    static NotFound(msg = 'Not Found') {
        return new ApiError(msg, 404);
    }
    static Internal(msg = 'Internal Server Error') {
        return new ApiError(msg, 500);
    }
}

module.exports = ApiError;